package cn.com.cifi.mars.service.impl;

import cn.com.cifi.mars.entity.common.ProjectByStages;
import cn.com.cifi.mars.mapper.mars.ProjectByStagesMapper;
import cn.com.cifi.mars.util.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.cifi.mars.entity.VersionLog;
import cn.com.cifi.mars.mapper.mars.VersionLogMapper;
import cn.com.cifi.mars.service.VersionLogService;

import java.time.LocalDateTime;

/**
 * <p>
 * 版本日志表 服务实现类
 * </p>
 *
 * @author plx
 * @since 2020-02-27
 */
@Service
public class VersionLogServiceImpl extends ServiceImpl<VersionLogMapper, VersionLog> implements VersionLogService {

    @Autowired
    private VersionLogMapper versionLogMapper;

    @Autowired
    private ProjectByStagesMapper projectByStagesMapper;

    @Override
    public void saveVersionLogInfo(String projectId, String projectFid, String moduleType, String event,
                                   String versionId, String versionName, String beforeState, String AfterState,
                                   String modifySourceType, String modifySourceId, String operationBy,
                                   LocalDateTime operationTime, String title, String content, int isDel,
                                   String createBy, LocalDateTime createTime) {
        VersionLog versionLog = new VersionLog();

        //根据项目id查询区域信息
        ProjectByStages projectByStages = projectByStagesMapper.selectRegionByProjectId(projectId);
        if(projectByStages != null){
            versionLog.setRegionId(projectByStages.getOrgdepid());
        }

        versionLog.setId(UUIDUtils.create());
        versionLog.setProjectId(projectId);
        versionLog.setProjectfId(projectFid);
        versionLog.setModuleType(moduleType);
        versionLog.setEvent(event);
        versionLog.setVersionId(versionId);
        versionLog.setVersionName(versionName);
        versionLog.setBeforeState(beforeState);
        versionLog.setAfterState(AfterState);
        versionLog.setModifySourceType(modifySourceType);
        versionLog.setModifySourceId(modifySourceId);
        versionLog.setOperationBy(operationBy);
        versionLog.setOperationTime(operationTime);
        versionLog.setTitle(title);
        versionLog.setContent(content);
        versionLog.setIsDelete(isDel);
        versionLog.setCreateBy(createBy);
        versionLog.setCreateTime(createTime);

        versionLogMapper.insert(versionLog);
    }
}
